package com.yxhl.zoume.core.specialcar.presenter;

import android.content.Context;

import com.yxhl.zoume.common.presenter.BasePresenter;
import com.yxhl.zoume.common.ui.view.BaseView;
import com.yxhl.zoume.core.specialcar.view.SpecialCarPayView;
import com.yxhl.zoume.data.http.rest.param.specialcar.SpecialCarPayInfoParam;
import com.yxhl.zoume.data.http.rest.response.specialcar.SpecialCarPayInfoResponse;
import com.yxhl.zoume.domain.interactor.ZMSubscriber;
import com.yxhl.zoume.domain.interactor.car.specialcar.SpecialCarPayInfoUseCase;

import javax.inject.Inject;

/**
 * Created by vhawk on 2016/11/7.
 */

public class SpecialCarPayPresenter extends BasePresenter {

    @Inject
    SpecialCarPayInfoUseCase useCase;
    private SpecialCarPayView view;

    @Inject
    public SpecialCarPayPresenter(Context context) {
        super(context);
    }

    @Override
    public void attachView(BaseView view) {
        super.attachView(view);
        this.view = (SpecialCarPayView) view;
    }

    public void fetchSpecialCarPayInfo(int bizType, String totalFee, String couponId) {

        SpecialCarPayInfoParam payInfoParam = new SpecialCarPayInfoParam();

        payInfoParam
                .setCouponUserRelId(couponId)
                .setBizType(bizType)
                .setOrderTotalFee(totalFee)
                .setMobile(getMobile())
                .setToken(getToken());

        useCase.execute(payInfoParam, new ZMSubscriber<SpecialCarPayInfoResponse>() {
            @Override
            public void onNext(SpecialCarPayInfoResponse response) {
                super.onNext(response);
                if (response.isSucc()) {
                    view.handlePayInfoSucceed(response.getCouponInfo());
                } else {
                    view.handlePayInfoFailure(response.getResultMessage());
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                view.handlePayInfoError();
            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        useCase.unsubscribe();
    }
}
